﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command.MenuCommand;
using MediatR;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler.MenuCommandHandler
{
    public class GetMenuNameCommandHandler : IRequestHandler<GetMenuNameCommand, APIResult<List<MenuModel>>>
    {
        private readonly IBaseRepository<MenuModel> menuRepos;

        public GetMenuNameCommandHandler(IBaseRepository<MenuModel> menuRepos)
        {
            this.menuRepos = menuRepos;
        }

        public async Task<APIResult<List<MenuModel>>> Handle(GetMenuNameCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<MenuModel>> result = new APIResult<List<MenuModel>>();
            var list = menuRepos.GetAll().Result;
            result.data = list.ToList();
            return await Task.FromResult(result);   
        }
    }
}
